//Copyright 2012 Trevin Liberty
//GNU GPL v3
//Author: Trevin Liberty
//
//Used when an object has an Animation that needs to be shown.

#ifndef ANIMATOR_H
#define ANIMATOR_H

#include <vector>

#include "../Structs.h"

using std::vector;

//The struct used to represent an objects bitmaps
struct Slide {
	ALLEGRO_BITMAP* image;
	int numSlides;
	int slideHeight;
	int slideWidth;
};

//SEE: Top of File
class Animator {
private:
	Slide* currentSlide;

	int maxFrame;
	int curFrame;

	int direction;

	float lastUpdate;
	float maxTime;

	bool ok;

public:
	//Constructor
	Animator() : currentSlide(NULL),
				 curFrame(0),
				 maxTime(.1),
				 direction(1),
				 lastUpdate(al_get_time()),
				 ok(false) {};

	//If the animation has multiple directions involved, use this.
	//SEE Entity.h
	//enum Direction {N, S, E, W, NE, NW, SE, SW};
	//				 {1, 2, 3, 4, 5, 6, 7, 8}
	//	PARAMS:
	//int i: <SEE: Direction>; 0 < i < 8
	void setDirection(int i);

	//Set the Slide for the animator to show.
	//	PARAMS:
	//Slide* images: SEE: struct Slide
	//float minTime: In seconds. The minimum time before the image changes.
	void setSlide(Slide* images, float minTime);

	//Returns the current slide number
	int getCurrSlideNumber() {return curFrame;}

	//Returns a bitmap image of the object given the set slide,
	//	current frame number, and min time.
	//SEE: setDirection(...), setSlide(...), 
	ALLEGRO_BITMAP* getImage();

	//Stops the Animator.
	//This keeps the current slide number form incrementing.
	//getImage() will always return the same slide.
	void stop() {ok = true;}

	//Starts the Animator.
	void go() {ok = false;}

	//Starts the Animator over.
	void reset() {curFrame = 0;}
};

#endif